// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SYS_INFO
// * CreateDate    : 2013-08-28 11:00:58
// * Creater       : CodeSmith
// * LastChangeDate: 2013-08-28 11:00:58
// * LastChanger   : 2013-08-28 11:00:58
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sys
{
/// <summary>
    /// SysInfo
    /// </summary>
    public partial class SysInfoBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSysInfoEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SysInfoEntity GetSysInfo(SysInfoEntity objSysInfoEntity)
        {
            return DataAccess.SelectSingle<SysInfoEntity>(objSysInfoEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSysInfoEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static SysInfoEntity InsertSysInfo(SysInfoEntity objSysInfoEntity)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    if (objSysInfoEntity.IsActive == 1)
                    {
                        string sql = "update sys_info set is_active=0";
                        broker.ExecuteSQL(sql);
                    }
                    objSysInfoEntity.Id = Guid.NewGuid().ToString();
                    DataAccess.Insert(objSysInfoEntity);
                    broker.Commit();
                    return objSysInfoEntity;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool InsertSysInfo(List<SysInfoEntity> objSysInfoEntityList)
        {
            return DataAccess.Insert(objSysInfoEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSysInfoEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSysInfo(SysInfoEntity objSysInfoEntity)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    if (objSysInfoEntity.IsActive == 1)
                    {
                        string sql = "update sys_info set is_active=0 where id!='"+objSysInfoEntity.Id+"'";
                        broker.ExecuteSQL(sql);
                    }
                    DataAccess.Update(objSysInfoEntity);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool UpdateSysInfo(List<SysInfoEntity> objSysInfoEntityList)
        {
            return DataAccess.Update<SysInfoEntity>(objSysInfoEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSysInfoEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSysInfo(SysInfoEntity objSysInfoEntity)
        {
            return DataAccess.Delete(objSysInfoEntity);
        }

        public static bool DeleteSysInfo(List<SysInfoEntity> objSysInfoEntityList)
        {
            return DataAccess.Delete<SysInfoEntity>(objSysInfoEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSysInfoAll()
        {
            return DataAccess.SelectAllDataSet<SysInfoEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SysInfoEntity> GetSysInfoAllList()
        {
            return DataAccess.SelectAll<SysInfoEntity>();
        }
        #endregion


        #region GetPage
        public static DataSet GetSysInfoPages(int pageIndex,int pageCount)
        {
            string sql = @"select top {0} *,(select count(1) from sys_info) as cnt
from sys_info
where id not in (
    select top ({1}*({2}-1)) id from sys_info order by created_date
) order by created_date";
            sql = string.Format(sql, pageCount, pageCount, pageIndex);
            return DataAccess.SelectDataSet(sql);
        }
        #endregion
    }
	
	
}	

